// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:inventory_system/main.dart';

void main() {
  testWidgets('Login screen UI elements test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(const MyApp());

    // 测试基本UI元素是否存在
    expect(find.byType(TextFormField), findsWidgets); // 用户名和密码字段
    expect(find.byType(ElevatedButton), findsWidgets); // 登录按钮
    expect(find.byType(Checkbox), findsOneWidget); // "记住我"复选框
    
    // 测试特定的文本元素（注意：维吾尔文字符串）
    expect(find.text('سىستېمىغا خۇش كەلدىڭىز'), findsOneWidget); // "欢迎使用系统"
    expect(find.text('مېنى ئەستە تۇت'), findsOneWidget); // "记住我"
    expect(find.text('پارول ئۇنتۇلغان؟'), findsOneWidget); // "忘记密码?"
    
    // 测试图标是否存在
    expect(find.byIcon(Icons.person_outline), findsOneWidget); // 用户名图标
    expect(find.byIcon(Icons.lock_outline), findsOneWidget); // 密码图标
    expect(find.byIcon(Icons.visibility_outlined), findsOneWidget); // 显示密码图标
  });
  
  testWidgets('Login form interaction test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(const MyApp());
    
    // 输入用户名
    await tester.enterText(find.byType(TextFormField).first, 'testuser');
    
    // 输入密码
    await tester.enterText(find.byType(TextFormField).last, 'password123');
    
    // 点击"记住我"复选框
    await tester.tap(find.byType(Checkbox));
    await tester.pump();
    
    // 点击登录按钮
    await tester.tap(find.byType(ElevatedButton));
    await tester.pumpAndSettle();
    
    // 验证表单互动正常
    // 这里我们可以添加更多的验证，根据登录处理逻辑
  });
}
